package cn.iotab.iotkit.transport.api.access.model.custom.function;

import cn.iotab.iotkit.transport.api.access.model.custom.ProtocolConstant;
import cn.iotab.iotkit.transport.api.access.model.message.CommonDeviceMessage;
import cn.iotab.iotkit.transport.api.access.model.message.OriginMessage;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils;

/**
 * 平台 -> 设备
 */
@Getter
@Setter
public class FunctionInvokeMessage extends CommonDeviceMessage{

    private String functionId;


    @Override
    public OriginMessage toOriginMessage() {
        String type = ProtocolConstant.FUNC_PREFIX + functionId;
        setOriginType(type);
        return super.toOriginMessage();
    }

    @Override
    public void fromOriginMessage(String productKey, String deviceId, OriginMessage message) {
        super.fromOriginMessage(productKey, deviceId, message);
        String type = getOriginType();
        functionId = StringUtils.substring(type, ProtocolConstant.FUNC_PREFIX.length());
    }

}
